package com.lly.schedule.filters;

import com.lly.schedule.pojo.SysUser;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
//@WebFilter(urlPatterns = {"/showSchedule.html","/syschdeule/*"})
public class Loginfilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //1.父转子
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        //2.获取session
        HttpSession session = request.getSession();
        SysUser sysUser = (SysUser)session.getAttribute("sysUser");
        if(sysUser != null){
            //放行
            filterChain.doFilter(request,response);
        }else{
            //重定向
            response.sendRedirect("login.html");
        }
    }
}
